<template>
  <div class="self-evaluation">
    <h3>自我评价</h3>
    <el-form :model="evaluationForm" label-width="0px">
      <el-form-item>
        <el-input type="textarea" v-model="evaluationForm.content" :rows="5" placeholder="请输入自我评价（500字以内）"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="generateResponse">AI润色</el-button>
      </el-form-item>
      <el-form-item>
        <h4>回复：</h4>
        <p>{{ responseMessage }}</p>
        <el-input type="textarea" v-model="extendedResponse" :rows="5" placeholder="扩写后的内容"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      evaluationForm: {
        content: ''
      },
      responseMessage: '', // 响应消息
      extendedResponse: '' // 扩展消息
    };
  },
  methods: {
    generateResponse() {
      axios.post('http://localhost:8000/api/generate_response', { user_input: this.evaluationForm.content })
        .then(response => {
          console.log('API响应数据:', response.data); // 输出API响应数据以进行调试
          
          if (response.data && response.data.message && response.data.extended) {
            this.responseMessage = response.data.message; 
            this.extendedResponse = response.data.extended;
            console.log('设置的responseMessage:', this.responseMessage); // 输出设置的响应消息
            console.log('设置的extendedResponse:', this.extendedResponse); // 输出设置的扩展消息
          } else {
            console.error('响应数据格式不正确:', response.data);
          }
        })
        .catch(error => {
          console.error('生成回复时出错:', error);
        });
    }
  }
};
</script>

<style scoped>
/* 添加任何必要的样式 */
</style>

